#include <iostream>
#include <vector>
using namespace std;
class Matrix {
private:
    vector<vector<double>> data;
    int rows;
    int cols;
public:
    //构造函数，创建指定行和列的矩阵，并将元素初始化为 0
    Matrix(int row, int col) : rows(row), cols(col), data(row, vector<double>(col, 0)) {}
    //重载 () 运算符，用于访问矩阵元素
    double& operator()(int i, int j) {
        return data[i][j];
    }                   
    //重载输入运算符 >>
    friend istream& operator>>(istream& in, Matrix& m) {
        for (int i = 0; i < m.rows; ++i) {
            for (int j = 0; j < m.cols; ++j) {
                in >> m.data[i][j];
            }
        }
        return in;
    }
    //重载输出运算符 <<
    friend ostream& operator<<(ostream& out, const Matrix& m) {
        for (int i = 0; i < m.rows; ++i) {
            for (int j = 0; j < m.cols; ++j) {
                out << m.data[i][j] << " ";
            }
            out << endl;
        }
        return out;
    }
    // 重载 += 运算符
    Matrix& operator+=(const Matrix& other) {
        if (rows!= other.rows || cols!= other.cols) {
            cout<< "ERROR!" <<endl;
            return *this;
        
        }
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                data[i][j] += other.data[i][j];
            }
        }
        cout << *this;
        return *this;
    }
    // 重载 *= 运算符
    Matrix& operator*=(const Matrix& other) {
        if (cols!= other.rows) {
            cout << "ERROR!" <<endl;
            return *this;
        }
        Matrix result(rows, other.cols);
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < other.cols; ++j) {
                for (int k = 0; k < cols; ++k) {
                    result.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        *this = result;
        cout << *this;
        return *this;
    }
    // 重载 = 运算符
    Matrix& operator=(const Matrix& other) {
        if (this == &other) {
          return *this;
        }
        rows = other.rows;
        cols = other.cols;
        data = other.data;
        return *this;
    }
};
int main() {
    int row1, col1, row2, col2;
    cin >> row1 >> col1;
    Matrix table1(row1, col1);
    cin >> table1;
    cin >> row2 >> col2;
    Matrix table2(row2, col2);
    cin >> table2;
    
    cout << table1(row1 / 2, col1 / 2) <<endl; 
   
    table1 *= table2;
    table1 += table2;  
    table1 = table2;
    cout << table1;    
    return 0;
}
